package ar.com.tristeslos3tigres.radioapp;

import java.util.List;

import android.app.ListActivity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.TextView;
import ar.com.tristeslos3tigres.radioapp.R;
import ar.com.tristeslos3tigres.radioapp.adapters.ProgramacionParserDom;
import ar.com.tristeslos3tigres.radioapp.entities.Programa;

public class ProgramacionActivity extends ListActivity {

	private Button btnCargar;
	private TextView txtResultado;

	private List<Programa> programas;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//setContentView(R.layout.rss_info);

		
				ProgramacionParserDom saxparser = new ProgramacionParserDom(
						"http://www.fevemplas.com.ar/programacion.xml");

				programas = saxparser.parse();

				

				getListView().setAdapter(new CustomAdapter_iconrowRss(this, programas));
	}

	public class CustomAdapter_iconrowRss extends BaseAdapter
			implements Filterable {
		/**
 * 
 */
		private Context mContext;
		private List<Programa> list_programas;

		public CustomAdapter_iconrowRss(Context context,
				List<Programa> programaList) {
			// super(context, R.layout.simpleiconrow, list);
			// super();
			mContext = context;
			this.list_programas = programaList;

		}

		public View getView(final int position, View v, ViewGroup parent) {
			View mView = v;
			if (mView == null) {
				LayoutInflater vi = (LayoutInflater) mContext
						.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
				mView = vi.inflate(R.layout.iconrow_rss, null);
			}

			TextView tv_nombre = (TextView) mView
					.findViewById(R.id.iconrow_rss_titulo);
			TextView tv_descripcion = (TextView) mView
					.findViewById(R.id.iconrow_rss_descripcion);
			TextView tv_dia = (TextView) mView
					.findViewById(R.id.iconrow_rss_dia);
			TextView tv_hora = (TextView) mView
					.findViewById(R.id.iconrow_rss_hora);

			

			

			if (list_programas.get(position) != null) {
				
				tv_nombre.setText(list_programas.get(position).getNombre_programa());

				tv_descripcion.setTextColor(Color.BLACK);

				tv_dia.setText(list_programas.get(position).getDia());
				
				String hr_desde=  list_programas.get(position).getHora_desde();
				String hr_hasta=  list_programas.get(position).getHora_hasta();
				
				tv_hora.setText("De "+hr_desde +" a "+hr_hasta);
				tv_descripcion.setText(list_programas.get(position).getDescripcion_programa());
				
				

				
			}

			

			return mView;
		}
		
		

		public int getCount() {
			return list_programas.size();
		}

		public Object getItem(int position) {
			return list_programas.get(position);
		}

		public long getItemId(int position) {
			return position;
		}

		@Override
		public Filter getFilter() {
			// TODO Auto-generated method stub
			return null;
		}

		

	}
/*
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}*/
}
